Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • James Feeney 26 posts 166 karma points
    Sep 12, 2013 @ 16:36
    James Feeney
    0

    Code block is missing "}" character??

    My code below is causing errors with missing "}". But I don't know how to fix it, all my brackets close from what I can see. Could someone take a look & help? Thanks in advance.

    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @* get strings from url, if existing *@
    @{
        string collect = String.Format("{0}", Request.QueryString["Bottle"]);
        var rows = 0;
        var rowNum = 0;
        var numInRow = 3;
        var tr = 0;    
    
        if (!string.IsNullOrEmpty(Request.QueryString["Bottle"])) {
    
            var rep = CurrentModel.DescendantsOrSelf().Items.SingleOrDefault(x => x.Name == collect);
    
            if (rep != null) {
    
                for (int i = 0; i rep.Count() / numInRow; i++) {
    
                    int s = i * numInRow;
    
                    if (rows == 0) {
    rowNum++; } if (rows == 1) {
    rowNum--; } foreach (var node in rep.Skip(s).Take(numInRow)) { @* DO LOTS WITH EVERY ITEM *@ }
    if (rows == 0){rows++;} else {rows--;}
    tr++; } } } }
  • Jamie Pollock 174 posts 853 karma points c-trib
    Sep 12, 2013 @ 18:09
    Jamie Pollock
    0

    Hey James, I'm not sure about missing a closing brace, but in the for loop it's missing a conditional.

    The fix

      i <some conditional> rep.Count()
    

    Rather than

      i rep.Count()
    

    Complete code

      @using umbraco.MacroEngines
      @inherits umbraco.MacroEngines.DynamicNodeContext
    
      @* get strings from url, if existing *@
      @{
          string collect = String.Format("{0}", Request.QueryString["Bottle"]);
          var rows = 0;
          var rowNum = 0;
          var numInRow = 3;
          var tr = 0;    
    
          if (!string.IsNullOrEmpty(Request.QueryString["Bottle"])) {
    
              var rep = CurrentModel.DescendantsOrSelf().Items.SingleOrDefault(x => x.Name == collect);
    
              if (rep != null) {
    
                  for (int i = 0; i <some conditional> rep.Count() / numInRow; i++) {
    
                      int s = i * numInRow;
    
                      if (rows == 0) {
                          rowNum++;
                      }
    
                      if (rows == 1) {
                       rowNum--;
                      }
    
                      foreach (var node in rep.Skip(s).Take(numInRow)) {
                          @* DO LOTS WITH EVERY ITEM *@   
                      }
    
                    if (rows == 0){rows++;} else {rows--;}
    
                    tr++; 
                  }
              }
          }
      }
    

    I hope this helped, mate.

    Jamie

  • James Feeney 26 posts 166 karma points
    Sep 12, 2013 @ 18:23
    James Feeney
    0

    Thanks Jamie! Didn't see that. I'm now getting this:

    Error occured

    ...\635146033346293678_Results.cshtml(18): error CS1061: 'umbraco.MacroEngines.DynamicNode' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'umbraco.MacroEngines.DynamicNode' could be found (are you missing a using directive or an assembly reference?)

    Am I missing a @using or @inherit reference at the top? 

  • Jamie Pollock 174 posts 853 karma points c-trib
    Sep 12, 2013 @ 18:38
    Jamie Pollock
    100

    Hi James, Nope not at all. It's because you're setting rep via

    SingleOrDefault(x => x.Name == collect)
    

    which will always return a single node. If you want to return a collection of nodes you should use

    Where(x => x.Name == collect)
    

    Count is only available to IEnumerables or collections.

    Jamie

Please Sign in or register to post replies

Write your reply to:

Draft